home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.std.c
- Subject: Re: Array vs. structure alignment
- Date: 05 Mar 1996 14:13:17 GMT
- Organization: Los Alamos National Laboratory
- Distribution: world
- Message-ID: <TANMOY.96Mar5071317@qcd.lanl.gov>
- References: <1996Mar5.114346.1790@ittpub>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: wil@ittpub.nl's message of 5 Mar 96 11:43:46 WET
-
- In article <1996Mar5.114346.1790@ittpub>
- wil@ittpub.nl (Wil Evers) writes:
- <snip>
- WE: 1. Is there any technical reason why the memory layouts of CUSTOMER_TYPE
- WE: and PROPER_CUSTOMER_TYPE would be different? It seems to me that wrapping
- WE: an array into a structure is something relevant at compile-time, not at
- WE: run time. IMHO the generated code for accessing the fields in a
- WE: CUSTOMER_TYPE could be exactly the same as the code for accessing the
- WE: fields in a PROPER_CUSTOMER_TYPE.
-
- Because the easiest implementations need the representation of all
- struct types to be identical, maybe your compiler is trying to enforce
- their alignment as identical too? Why? You don't seem to be on a
- machine where the generation of an unaligned pointer (rather than its
- dereference) will create a hardware fault.
-
- But, in any case, wrapping an array in a struct may introduce padding
- at the end.
-
- WE:
- WE: 2. Assuming there is no technical reason for this difference, shouldn't
- WE: the C standard require that the layouts of these two types be the same?
- WE: [Please don't ask me for an exact phrasing - I'll happily leave that to
- WE: the experts.]
-
- The C standards committee has been very unwilling to put absolutely
- any limits on the implementation decision to introduce padding. I do
- believe that a quality implementation should provide a pragma
- (yecchhh)/compiler switch to pack structs: but that has little to do
- with comp.std.c
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-